package N2024.M11.D28;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Condition;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2025-02-04
 * Time: 22:21
 */
public class test2 {
    private static final ReentrantLock lock1 = new ReentrantLock();
    private static final ReentrantLock lock2 = new ReentrantLock();

    public static void main(String[] args) {
        Thread thread1=new Thread(()->{
           lock1.lock();
           System.out.println("锁1获取");
           lock2.lock();
           System.out.println("锁2获取");
           lock2.unlock();
           lock1.unlock();
        });

        Thread thread2=new Thread(()->{
            lock2.lock();
            System.out.println("锁2获取");
            lock1.lock();
            System.out.println("锁1获取");
            lock1.unlock();
            lock2.unlock();
        });

        thread1.start();
        thread2.start();
    }
}
